package com.wb.cloud_provider.service;

import com.wb.cloud_provider.bean.Movie;
import com.wb.cloud_provider.dao.TypeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;

import java.util.List;

@Service
public class TypeService {

    @Autowired
    private TypeDao typeDao;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public List<Movie> SelectMovie(Integer type_id){
          Gson gson=new Gson();
          String key="SelectMovie"+type_id;
          String s = stringRedisTemplate.boundValueOps(key).get();
          if(s==null || s.equals("")){

            List<Movie> movies = typeDao.SelectMovie(type_id);
            String s1 = gson.toJson(movies);
            stringRedisTemplate.boundValueOps(key).set(s1);
        }
        List list = gson.fromJson(s, List.class);
        return list;
    }
}
